/*
 * Function.c
 *
 *  Created on: 14/11/2011
 *      Author: marcio
 */

#include "Function.h"

Function* function_newfunction(int size, int (*fk)(void*, void*), int (*fi)(void*, void*)){
	Function* f = malloc(sizeof(Function));
	f->compimage = fi;
	f->compkey = fk;
	f->images = malloc(sizeof(List*) * size);
	for(int i = 0; i < size; i++) f->image[i] = list_newList();
	f->keys = malloc(sizeof(void*) * size);
	f->size = size;
	return f;
}

int function_add(Function* f, void* key, void* image){
	int test = 0, last = f->size;
	for(int i = 0; i < f->size; i++){
		if(f->keys[i] == NULL) last = i;
		if(f->compkey(key, f->keys[i])){
			list_add(f->images[i], image);
			test = 1;
		}
	}
	if(test == 1 && last < f->size){
		f->keys[last] = key;
		list_add(f->images[last], image);
	}
	return 0;
}

int function_remove(Function* f, void* key){
	//TODO
	return 0;
}

int function_getImage(Function* f, void* key, void** image){
	//TODO
	return 0;
}

int function_getKey(Function* f, void* image, void** key){
	//TODO
	return 0;
}

int function_delete(Function* f){
	//TODO
	return 0;
}
